package com.atguigu.wordcount.wccombine;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @ClassName WcReducer
 * @DeScription WcReducer
 * @Author 剧情再美终是戏
 * @Date 2019/11/16 14:48
 * @Version 1.0
 **/
public class WcReducer extends Reducer<Text, IntWritable, Text, IntWritable>{

    // 设置输出参数
    private IntWritable outVal = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

        // 记录当前key的总数
        int sum =0;

        // 获取map传过来的值 将map传过来的值进行统计
        for (IntWritable value : values) {
            sum += value.get();
        }

        // 将结果写出
        outVal.set(sum);
        context.write(key, outVal);
    }
}
